/* Copyright 2024 Coremail
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
export type AsyncHandler<T> = (code: number, response: T | null, message: string | null) => void

export class HandlerResult<T> {
  code: HandlerResultCode = HandlerResultCode.Ok
  response: T | null = null;
  message: string | null = null;
}

export class ActionResult<T> {
  status: number = 0;
  response: T | null = null;
  message: string | null = null;
}

export enum MailHandlerResultCode {
  Ok = 0,
  Error = -1
}

export enum HandlerResultCode {
  Ok = 0,
  Error = -1
}

/**
 *   = ["outlook.com", "hotmail.com"
 , "gmail.cn", "163.com", "126.com",
 "qq.com", "live.com", "live.cn"]
 */
export enum MailType {
  QQ,
  ICLOUD,
  OUTLOOK,
  HOTMAIL,
  GMAIL,
  MAIL163,
  MAIL126,
  SINA,
  LIVE,
  YAHOO,
  OTHER,
  MailTypeCount
}

export function idStringForType(type: MailType) : string {
  switch (type) {
    case MailType.QQ:
      return "qq"
    case MailType.ICLOUD:
      return "icloud"
    case MailType.OUTLOOK:
      return "outlook"
    case MailType.HOTMAIL:
      return "hotmail"
    case MailType.SINA:
      return "sina"
    case MailType.GMAIL:
      return "gmail"
    case MailType.MAIL163:
      return "163"
    case MailType.MAIL126:
      return "126"
    case MailType.LIVE:
      return "live"
    case MailType.YAHOO:
      return "yahoo"
    case MailType.OTHER:
    default:
      return "other"
  }
}

export enum MailFetchProtocol {
  POP3 = "pop3",
  IMAP = "imap",
  COREMAIL = "coremail",
  EXCHANGE = 'exchange'
}

export enum MailSendProtocol {
  SMTP,
  COREMAIL
}

export enum SslType {
  None,
  SslTls,
  StartTls
}


class MailSslType {
  sslType: number = 0
  sslStr: string = ''
}

const SslData: MailSslType[] = [{ sslType: 0, sslStr: "无" }
  , { sslType: 1, sslStr: "SSL/TLS" }, {
    sslType: 2,
    sslStr: "STARTTLS"
  }]


export class MailInPutProtocol {
  host: string = ""
  port: number = 0
  sslType: number = 0
}

export { SslData, MailSslType }